package com.adg.weather;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.text.Editable;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Login extends Activity {
	//Declaracion de Botones
	public Button btnArrancar;
	public Button btnRegistro;

	public Button btnShowLocation;
	GPS gps;
	
	//Metodo que se crea cuando se lanza la activity, y se hereda de la clase Activity
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_whoopi_weather);
		
		//Ligamos el boton creado
		btnArrancar=(Button) findViewById(R.id.entrar);	
		btnRegistro=(Button) findViewById(R.id.Registro);	

		final EditText user = (EditText) findViewById(R.id.Name);	
		final EditText password = (EditText) findViewById(R.id.Pass);	

		 //Creamos un listener que escuche siempre a ese boton y cuando se presione lanzamos la activity 
	       btnArrancar.setOnClickListener(new OnClickListener() {
	    	      public void onClick(View view) {
	    	    	  String nom=user.getText().toString();
	    	    	  
	    	    	  if(!user.getText().toString().equals("Oprah")){
	    	    		  Toast.makeText(Login.this, user.getText()+":Usuario Inexistente ",
	    	    					Toast.LENGTH_SHORT).show();	    	    		  
	    	    		  
	    	    	  }
	    	    	  else{
	    	    		  if(!password.getText().toString().equals("123")){
		    	    		  Toast.makeText(Login.this, user.getText()+"!!Password incorrecta!! ",
		    	    					Toast.LENGTH_SHORT).show();	    	    		  
		    	    		  
		    	    	  }else{
			    	    	  Arrancar();

		    	    	  }
	    	    		  
	    	    	  }
	    	   
	    	      	}
	       });
	       
	       btnRegistro.setOnClickListener(new OnClickListener() {
	    	      public void onClick(View view) {
	    	    	 
			    	    	  Registrar();
	    	   
	    	      }
	       });
//************************************************gps
	       /*
	       btnShowLocation = (Button) findViewById(R.id.btnGPS);
	       
	       
	        // show location button click event
	        btnShowLocation.setOnClickListener(new View.OnClickListener() {	 
	            
	            public void onClick(View arg0) {
	                // create class object
	                gps = new GPS(Login.this);
	 
	                // check if GPS enabled
	                if(gps.canGetLocation()){
	 
	                    double latitude = gps.getLatitude();
	                    double longitude = gps.getLongitude();
	                    // \n is for new line
	                    Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
	                }else{
	                    // can't get location
	                    // GPS or Network is not enabled
	                    // Ask user to enable GPS/network in settings
	                    gps.showSettingsAlert();
	                }
	 
	            }
	        });
	        
//***********************************************************	   */     
	}
	
	
	
 //Metodos que lanzan la activity 
    
    
    
    public void Arrancar() {
		Intent iniciaJuego = new Intent(this, MainActivity.class);
		startActivity(iniciaJuego);
	}
    
    public void Registrar() {
  		Intent iniciaJuego = new Intent(this, Registro.class);
  		startActivity(iniciaJuego);
  	}
	
		@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_whoopi_weather, menu);
		return true;
	}
}
